package com.example.uridemo0216;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.icu.util.Calendar;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import java.io.File;

public class MainActivity extends AppCompatActivity {
    public static final String MIME_TYPE_IMAGE_JPEG = "image/*";

    public static final int ACTIVITY_GET_IMAGE = 0;
    private static final int REQUSET_CODE_TO_PICTURE=0XF1;
    private Intent intent;
    private ImageView imageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button btn=findViewById(R.id.btn_1);
        imageView=findViewById(R.id.image_1);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //跳转网址
//                Uri uri=Uri.parse("http://www.baidu.com/");
//                startActivity(new Intent(Intent.ACTION_VIEW,uri));
                //跳转坐标
//                Uri uri = Uri.parse("geo:52.76,-79.0342");
//                startActivity(new Intent(Intent.ACTION_VIEW,uri));
                //打开拨号
//                Uri uri = Uri.parse("tel:10086");
//                Intent intent = new Intent(Intent.ACTION_DIAL, uri);
//                startActivity(intent);
                //发送短信
//                Uri uri = Uri.parse("tel:10086");
//                Intent it = new Intent(Intent.ACTION_VIEW,uri);
//                it.putExtra("sms_body", "信息内容...");
//                it.setType("vnd.android-dir/mms-sms");
//                startActivity(it);
                //发送短信

//                Uri uri= Uri.parse("tel:10086");
//                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
//                intent.putExtra("sms_body", "I come from http://www.android-study.com");
//                intent.setType("vnd.Android-dir/mms-sms");
                //选择图片1
//                Intent getImage = new Intent(Intent.ACTION_GET_CONTENT);
//                getImage.addCategory(Intent.CATEGORY_OPENABLE);
//                getImage.setType(MIME_TYPE_IMAGE_JPEG);
//                startActivityForResult(getImage, ACTIVITY_GET_IMAGE);
                //选择图片2
                intent=new Intent(Intent.ACTION_GET_CONTENT);
                intent.addCategory(Intent.CATEGORY_OPENABLE);
                intent.setType(MIME_TYPE_IMAGE_JPEG);
                startActivityForResult(Intent.createChooser(intent,"File Chooser"),REQUSET_CODE_TO_PICTURE);
                //调用系统相机应用程序，并存储拍下来的照片
//                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//                time = Calendar.getInstance().getTimeInMillis();
//                intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment
//                        .getExternalStorageDirectory().getAbsolutePath()+"/tucue", time + ".jpg")));
//                startActivityForResult(intent, ACTIVITY_GET_CAMERA_IMAGE);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (RESULT_OK==resultCode){
            switch (requestCode){
                case REQUSET_CODE_TO_PICTURE:
                    imageView.setImageURI(data.getData());
            }
        }
    }
}